import { api } from 'boot/axios'

api.interceptors.request.use(config => {
  const token = localStorage.getItem('token')
  if (token) {
    config.headers.Authorization = token
  }
  return config
})

// 获取展会详情
export function getExhibition(id) {
  return api.get('/api/exhibition/detail', { params: { id } })
}

// 创建展会
export function createExhibition(data) {
  return api.post('/api/exhibition/create', data)
}

// 更新展会
export function updateExhibition(id, data) {
  return api.post('/api/exhibition/save', {
    ...data,
    id
  })
}

// 删除展会
export function deleteExhibition(id) {
  return api.delete(`/api/exhibition/delete/${id}`)
}

// 获取展会列表
export function getExhibitionList(params) {
  return api.get('/api/exhibition/list', { params })
}

// 导入Excel文件
export function importExhibition(file) {
  const formData = new FormData()
  formData.append('file', file)
  return api.post('/api/exhibition/import', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 检查Excel文件
export function checkExhibition(file) {
  const formData = new FormData()
  formData.append('file', file)
  return api.post('/api/exhibition/checkexcel', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 导出Excel文件
export function exportExhibition(item) {
  if (item === 'excel') {
    return api.get('/api/exhibition/export?mode=excel')
  } else if (item === 'excel_industry') {
    return api.get('/api/exhibition/export?mode=excel_industry')
  } else if (item === 'txt') {
    return api.get('/api/exhibition/export?mode=txt')
  }
}



export function getExhibitionStatistics() {
  return api.get('/api/exhibition/statistics')
}

export function getExhibitionItems() {
  return api.get('/api/exhibition/exhibition-items')
}

export function getRegionMap() {
  return api.get('/api/exhibition/region-map')
}


export function getIndustryMap() {
  return api.get('/api/exhibition/industry-map')
}

